package by.gravity.drive_track.fragments;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.EditText;
import by.gravity.common.fragment.CommonDialogFragment;
import by.gravity.drive_track.AppIntents;
import by.gravity.drive_track.R;

public class FavoriteNameDialogFragment extends CommonDialogFragment implements AppIntents{

	public static final String TAG = FavoriteNameDialogFragment.class.getSimpleName();
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final EditText editText = new EditText(getActivity());
		editText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

		Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle(R.string.enter_name);
		builder.setView(editText);
		builder.setPositiveButton(R.string.ok, new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				Intent intent = new Intent(ADD_TO_FAVORITE_INTENT);
				intent.putExtra(ARG_POINT_NAME, editText.getText().toString());
				sendBroadcast(intent);
				dismiss();
			}
		}).setNegativeButton(R.string.cancel, new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				Intent intent = new Intent(CLOSE_DIALOG_INTENT);
				sendBroadcast(intent);
			}
		});
		getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
		return builder.show();

	}

}
